import { RouteObject, useRoutes } from 'react-router'
import Home from '../pages/home'
import Warehouse from '../pages/warehouse'
import { Spin } from 'antd'
import { Suspense } from 'react'
import Frame from '../pages/frame'


type ZoomRouter = Omit<RouteObject, 'children'> & {
  name?: string,
  children?: ZoomRouter[]
}

export const WmsRouterConfig: ZoomRouter[] = [
  {
    path: '/',
    element: <Frame />,
    children: [
      {
        path: '/frame/home',
        name: '',
        element: <Home />
      },
      {
        path: '/frame/warehouse/list',
        element: <Warehouse />
      }
    ]
  }, {
    path: '/home',
    name: '',
    element: <Home />

  }

]
export const ZoomWmsRouter: ZoomRouter[] = [
  {
    path: '/frame/home',
    name: '',
    element: <Home />
  },
  {
    path: '/frame/warehouse/list',
    element: <Warehouse />
  }
]

export const wmsRouter = () => {
  return ({
    path: '/',
    name: '中鼎平台',
    routes: [
      {
        path: '/frame/home',
        name: '首页'
      },
      {
        path: '/frame/warehouse',
        name: '仓库管理',
        children: [
          {
            path: '/frame/warehouse/list',
            name: '仓库列表'
          }
        ]
      }
    ]
  })
}


export const RouteView = () => {
  return (
    <Suspense fallback={<Spin size={'small'} tip={'loading'} />}>
      {useRoutes(WmsRouterConfig as RouteObject[])}
    </Suspense>
  )
}

